<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="190px">
      <el-form-item label="企业名称" prop="epName">
        <el-input
          v-model="queryParams.epName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业地址" prop="epAddress">
        <el-input
          v-model="queryParams.epAddress"
          placeholder="请输入企业地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="省" prop="epProvince">
        <el-input
          v-model="queryParams.epProvince"
          placeholder="请输入省"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市" prop="epCity">
        <el-input
          v-model="queryParams.epCity"
          placeholder="请输入市"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区" prop="epArea">
        <el-input
          v-model="queryParams.epArea"
          placeholder="请输入区"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="企业法人" prop="epLegalPerson">
        <el-input
          v-model="queryParams.epLegalPerson"
          placeholder="请输入企业法人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业联系电话" prop="epPhone">
        <el-input
          v-model="queryParams.epPhone"
          placeholder="请输入企业联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业邮箱" prop="epEmail">
        <el-input
          v-model="queryParams.epEmail"
          placeholder="请输入企业邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="经度" prop="epLg">
        <el-input
          v-model="queryParams.epLg"
          placeholder="请输入经度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="epLt">
        <el-input
          v-model="queryParams.epLt"
          placeholder="请输入纬度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="企业组织机构代码" prop="epOgCode">
        <el-input
          v-model="queryParams.epOgCode"
          placeholder="请输入企业组织机构代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="信用代码" prop="epCreditCode">
        <el-input
          v-model="queryParams.epCreditCode"
          placeholder="请输入统一社会信用代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="行业类型" prop="epIndustryCategory">
        <el-input
          v-model="queryParams.epIndustryCategory"
          placeholder="请输入行业类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="企业规模" prop="epScale">
        <el-select v-model="queryParams.epScale" placeholder="请选择" >
          <el-option
            v-for="dict in this.typeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="注册资本" prop="epRegisteredCapital">
        <el-input
          v-model="queryParams.epRegisteredCapital"
          placeholder="请输入注册资本"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="生产状态" prop="epStatus">
        <el-select v-model="queryParams.epStatus"  clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>-->
      <el-form-item label="企业环保监管级别" prop="epEnvLevel">
        <el-select v-model="queryParams.epEnvLevel" placeholder="请选择">
          <el-option
            v-for="dict in typeOptions_jgjb"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="企业环保负责人" prop="epEnvPeople">
        <el-input
          v-model="queryParams.epEnvPeople"
          placeholder="请输入企业环保负责人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业环保负责人联系电话" prop="epEnvPhone">
        <el-input
          v-model="queryParams.epEnvPhone"
          placeholder="请输入企业环保负责人联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="投产日期" prop="epProductTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.epProductTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择投产日期">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item label="生产状态" prop="epStatus">
        <el-select v-model="queryParams.epStatus" placeholder="请选择">
          <el-option
            v-for="dict in typeOptions_sczt"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="企业曾用名" prop="epFormerName">
        <el-input
          v-model="queryParams.epFormerName"
          placeholder="请输入企业曾用名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="企业简称" prop="epShortName">
        <el-input
          v-model="queryParams.epShortName"
          placeholder="请输入企业简称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="企业标签" prop="epLabel">
        <el-input
          v-model="queryParams.epLabel"
          placeholder="请输入企业标签"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="企业官方网站" prop="epWebsite">
        <el-input
          v-model="queryParams.epWebsite"
          placeholder="请输入企业官方网站"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业logo" prop="epLogo">
        <el-input
          v-model="queryParams.epLogo"
          placeholder="请输入企业logo"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前登录的企业用户" prop="epUserName">
        <el-input
          v-model="queryParams.epUserName"
          placeholder="请输入当前登录的企业用户"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="污染类型" prop="epType">
        <el-select v-model="queryParams.epType" placeholder="请选择">
          <el-option
            v-for="dict in typeOptions_wrlx"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="archiveList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" type="index" width="100" align="center">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="企业名称" align="center" prop="epName" />
      <el-table-column :formatter="typeFormat_wrlx" label="污染类型" align="center" prop="epType" />
<!--      <el-table-column label="企业地址" align="center" prop="epAddress" />-->
<!--      <el-table-column label="省" align="center" prop="epProvince" />
      <el-table-column label="市" align="center" prop="epCity" />
      <el-table-column label="区" align="center" prop="epArea" />-->
      <el-table-column label="企业法人" align="center" prop="epLegalPerson" />
      <el-table-column label="企业联系电话" align="center" prop="epPhone" />
<!--      <el-table-column label="企业邮箱" align="center" prop="epEmail" />-->
<!--      <el-table-column label="经度" align="center" prop="epLg" />-->
<!--      <el-table-column label="纬度" align="center" prop="epLt" />-->
<!--      <el-table-column label="企业组织机构代码" align="center" prop="epOgCode" />-->
<!--      <el-table-column label="统一社会信用代码" align="center" prop="epCreditCode" />-->
<!--      <el-table-column label="行业类型" align="center" prop="epIndustryCategory" />-->
      <el-table-column :formatter="typeFormat" label="企业规模" align="center" prop="epScale" />
      <el-table-column label="注册资本" align="center" prop="epRegisteredCapital" />
      <el-table-column :formatter="typeFormat_sczt" label="生产状态" align="center" prop="epStatus" />
      <el-table-column :formatter="typeFormat_jgjb" label="企业环保监管级别" align="center" prop="epEnvLevel" />
      <el-table-column label="企业环保负责人" align="center" prop="epEnvPeople" />
      <el-table-column label="企业环保负责人联系电话" align="center" prop="epEnvPhone" />
<!--      <el-table-column label="投产日期" align="center" prop="epProductTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.epProductTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
&lt;!&ndash;      <el-table-column label="是否注销(1,注销，0未注销)" align="center" prop="epLogoutStatus" />&ndash;&gt;
      <el-table-column label="企业曾用名" align="center" prop="epFormerName" />
      <el-table-column label="企业简称" align="center" prop="epShortName" />
      <el-table-column label="企业标签" align="center" prop="epLabel" />
      <el-table-column label="企业简介" align="center" prop="epIntroduction" />
      <el-table-column label="企业官方网站" align="center" prop="epWebsite" />
      <el-table-column label="企业生产经营地址" align="center" prop="epProductAddress" />
      <el-table-column label="企业logo" align="center" prop="epLogo" />
      <el-table-column label="当前登录的企业用户" align="center" prop="epUserName" />-->

<!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :disabled = "true" :rules="rules" class="clearfix" label-width="140px">
        <div class="content-left clearfix">
          <div class="title2"></div>
          <el-form-item label="企业名称" prop="epName">
            <el-input v-model="form.epName" placeholder="请输入企业名称"/>
          </el-form-item>
          <el-form-item label="区域选择" prop="epAddress">
            <el-row>
              <el-col>
                <div class="content-address">
                  <div>
                    <el-select v-model="form.epProvince" class="adress-select"
                               placeholder="请选择省" @change="chooseProvince">
                      <el-option v-for="item in provinceData" :key="item.code"
                                 :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </div>
                  <div>
                    <el-select v-model="form.epCity" class="adress-select"
                               placeholder="请选择市" @change="chooseCity">
                      <el-option v-for="item in cityData" :key="item.code"
                                 :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </div>
                  <div>
                    <el-select v-model="form.epArea" class="adress-select"
                               placeholder="请选择区">
                      <el-option v-for="item in areaData" :key="item.code"
                                 :label="item.name" :value="item.code"></el-option>
                    </el-select>
                  </div>
                </div>
              </el-col>
            </el-row>


          </el-form-item>
          <el-form-item label="注册地址" prop="epArea">
            <el-input v-model="form.epAddress" placeholder="请输入注册地址"  type="textarea"/>
          </el-form-item>
          <el-form-item label="法人" prop="epLegalPerson">
            <el-input v-model="form.epLegalPerson" placeholder="请输入企业法人"/>
          </el-form-item>
          <el-form-item label="常用联系电话" prop="epPhone">
            <el-input v-model="form.epPhone" placeholder="请输入联系电话"/>
          </el-form-item>
          <el-form-item label="常用邮箱" prop="epEmail">
            <el-input v-model="form.epEmail" placeholder="请输入邮箱"/>
          </el-form-item>
          <el-form-item label="经纬度" prop="epLg">
            <el-row>
              <el-col>
                <div class="weidu">
                  <div style="width: 38%">

                    <el-input v-model="form.epLg" placeholder="请输入经度"/>
                  </div>
                  <div style="width: 38%">
                    <el-input v-model="form.epLt" placeholder="请输入纬度"/>
                  </div>

<!--                  <div style="width: 20%; text-align: center;height: 36px;" @click="outerVisible=true">
                    <el-button size="small" style="height: 34px;" type="primary">定位选择</el-button>
                  </div>-->
                </div>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item label="行业类型" prop="epIndustryCategory">
            <el-cascader
              ref="cascader"
              v-model="hangyeArr"
              :options="hangye"
              :props="{ checkStrictly: true }"
              clearable
              style="width: 100%"
              @change="handleAddressFun">
            </el-cascader>
          </el-form-item>
          <el-form-item label="企业规模" prop="epScale">
            <el-select v-model="form.epScale" placeholder="请选择" >
              <el-option
                v-for="dict in this.typeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="污染类型" prop="epType">
            <el-select v-model="form.epType" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_wrlx"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div class="content-middle">
          <div class="title2">&nbsp;</div>
          <el-form-item label="曾用名" prop="epFormerName">
            <el-input v-model="form.epFormerName" placeholder="请输入企业曾用名"/>
          </el-form-item>
          <el-form-item label="统一社会信用代码" prop="epCreditCode">
            <el-input v-model="form.epCreditCode" placeholder="请输入统一社会信用代码"/>
          </el-form-item>
          <el-form-item label="生产状态" prop="epStatus">
            <el-select v-model="form.epStatus" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_sczt"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="环保监管级别" prop="epEnvLevel" >
            <el-select v-model="form.epEnvLevel" placeholder="请选择">
              <el-option
                v-for="dict in typeOptions_jgjb"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="环保负责人" prop="epEnvPeople">
            <el-input v-model="form.epEnvPeople" placeholder="请输入企业环保负责人"/>
          </el-form-item>
          <el-form-item label="环保负责人电话" prop="epEnvPhone">
            <el-input v-model="form.epEnvPhone" placeholder="请输入企业环保负责人联系电话"/>
          </el-form-item>
          <el-form-item label="投产日期" prop="epProductTime">
            <el-date-picker v-model="form.epProductTime" clearable
                            placeholder="选择投产日期"
                            size="small"
                            style="width: 100%"
                            type="date" value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="注册资本(万元)" prop="epRegisteredCapital">
            <el-input v-model="form.epRegisteredCapital" placeholder="请输入注册资本" type="number"/>
          </el-form-item>
        </div>
        <div class="content-right">
          <div class="title2"><span></span>简介信息</div>
          <el-form-item label="企业logo" prop="epLogo" style="height: 168px">
            <el-row style=" width: 50%">
              <el-col>
                <div style="border: 1px solid #ccc; ">
                  <div :disabled="disableStus">
                    <ImageUpload v-model="form.epLogo"/>
                  </div>
                </div>
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item label="企业简介" prop="epIntroduction" style="margin-top:10px">
            <el-input v-model="form.epIntroduction" :rows="5" placeholder="请输入内容" type="textarea"/>
          </el-form-item>
          <el-form-item label="官方网站" prop="epWebsite">
            <el-input v-model="form.epWebsite" placeholder="请输入企业官方网站"/>
          </el-form-item>
          <el-form-item label="生产经营地址" prop="epProductAddress">
            <el-input v-model="form.epProductAddress":rows="3" placeholder="请输入内容" type="textarea"/>
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {addInfo, exportInfo, getInfo, InfoItem,listInfo,updateInfo,importTemplate,listInfo_common} from "@/api/enterprise/info";
import {delInfo} from "../../../api/enterprise/info";

export default {
  name: "Archive",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业基本信息表格数据
      archiveList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        epName: null,
        epAddress: null,
        epProvince: null,
        epCity: null,
        epArea: null,
        epLegalPerson: null,
        epPhone: null,
        epEmail: null,
        epLg: null,
        epLt: null,
        epOgCode: null,
        epCreditCode: null,
        epIndustryCategory: null,
        epScale: null,
        epRegisteredCapital: null,
        epStatus: null,
        epEnvLevel: null,
        epEnvPeople: null,
        epEnvPhone: null,
        epProductTime: null,
        epLogoutStatus: null,
        epFormerName: null,
        epShortName: null,
        epLabel: null,
        epIntroduction: null,
        epWebsite: null,
        epProductAddress: null,
        epLogo: null,
        epUserName: null,
        epType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      typeOptions:[],
      typeOptions_wrlx:[],
      typeOptions_sczt:[],
      typeOptions_jgjb:[]
    };
  },
  created() {
    this.getList();
    this.getDicts("qygm").then(response => {
      this.typeOptions = response.data;
    });
    this.getDicts("wrlx").then(response => {
      this.typeOptions_wrlx = response.data;
    });
    this.getDicts("sczt").then(response => {
      this.typeOptions_sczt = response.data;
    });
    this.getDicts("jgjb").then(response => {
      this.typeOptions_jgjb = response.data;
    });
  },
  methods: {
    /** 查询企业基本信息列表 */
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.epScale);
    },
    typeFormat_wrlx(row, column) {
      return this.selectDictLabel(this.typeOptions_wrlx, row.epType);
    },
    typeFormat_sczt(row, column) {
      return this.selectDictLabel(this.typeOptions_sczt, row.epStatus);
    },
    typeFormat_jgjb (row, column) {
      return this.selectDictLabel(this.typeOptions_jgjb, row.epEnvLevel);
    },
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.archiveList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        epId: null,
        epName: null,
        epAddress: null,
        epProvince: null,
        epCity: null,
        epArea: null,
        epLegalPerson: null,
        epPhone: null,
        epEmail: null,
        epLg: null,
        epLt: null,
        epOgCode: null,
        epCreditCode: null,
        epIndustryCategory: null,
        epScale: null,
        epRegisteredCapital: null,
        epStatus: "0",
        epEnvLevel: null,
        epEnvPeople: null,
        epEnvPhone: null,
        epProductTime: null,
        epLogoutStatus: "0",
        epFormerName: null,
        epShortName: null,
        epLabel: null,
        epIntroduction: null,
        epWebsite: null,
        epProductAddress: null,
        epLogo: null,
        epUserName: null,
        epType: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.epId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const epId = row.epId || this.ids
      getInfo(epId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "  企业基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.epId != null) {
            updateInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const epIds = row.epId || this.ids;
      this.$confirm('是否确认删除企业基本信息编号为"' + epIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(epIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有企业基本信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
<style>
.weidu {
  display: flex;
}
</style>
